package com.zhz.system.repository.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhz.common.tool.mybatisplus.base.dal.entity.BasePO;
import com.zhz.common.tool.mybatisplus.base.dal.repository.impl.BaseRepositoryImpl;
import com.zhz.model.system.RolePermission;
import com.zhz.model.system.contract.dto.RolePermissionDTO;
import com.zhz.model.system.contract.param.RolePermissionQueryParam;
import com.zhz.system.repository.dao.RolePermissionDao;
import com.zhz.system.repository.service.RolePermissionService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 角色权限表 服务实现类
 *
 * @author zhouhengzhe
 * @date 2023/4/30
 */
@Service
public class RolePermissionServiceImpl extends BaseRepositoryImpl<RolePermissionDao, RolePermissionDTO, RolePermission, RolePermissionQueryParam> implements RolePermissionService {
    @Override
    protected QueryWrapper<RolePermission> getWrapper(RolePermissionQueryParam queryParam) {
        return new QueryWrapper<RolePermission>()
                .eq(StringUtils.isNotBlank(queryParam.getId()), BasePO.ID, queryParam.getId())
                .eq(StringUtils.isNotBlank(queryParam.getRoleId()), RolePermission.ROLE_ID, queryParam.getRoleId())
                .eq(StringUtils.isNotBlank(queryParam.getPermissionId()), RolePermission.PERMISSION_ID, queryParam.getPermissionId())
                .in(CollectionUtils.isNotEmpty(queryParam.getPermissionIdSet()), RolePermission.PERMISSION_ID, queryParam.getPermissionIdSet())
                .in(CollectionUtils.isNotEmpty(queryParam.getRoleIdSet()), RolePermission.ROLE_ID, queryParam.getRoleIdSet());
    }
}
